from pydantic import BaseModel
from datetime import datetime


class NoteBase(BaseModel):
    """
    笔记基础模型类，定义了笔记的基本属性结构

    Attributes:
        user_id (int): 用户ID，标识笔记所属的用户
        category (str | None): 笔记分类，可选字段
        title (str | None): 笔记标题，可选字段
        content (str | None): 笔记内容，可选字段
        is_published (bool): 是否发布，默认为False
    """
    user_id: int
    category: str | None = None
    title: str | None
    content: str | None = None
    is_published: bool = False


class NoteCreate(NoteBase):
    """
    笔记创建模型类，继承自NoteBase
    用于创建新笔记时的数据验证和结构定义
    """
    pass


class NoteUpdate(BaseModel):
    """
    笔记更新模型类，定义了可更新的笔记字段

    Attributes:
        category (str | None): 笔记分类，可选字段
        title (str | None): 笔记标题，可选字段
        content (str | None): 笔记内容，可选字段
        is_published (bool | None): 是否发布状态，可选字段
    """
    category: str | None = None
    title: str | None = None
    content: str | None = None
    is_published: bool | None = None


class Note(NoteBase):
    """
    完整笔记模型类，包含所有笔记信息

    Attributes:
        id (int): 笔记唯一标识符
        created_at (datetime): 笔记创建时间
        updated_at (datetime): 笔记最后更新时间
        user_id (int): 用户ID，继承自NoteBase
        category (str | None): 笔记分类，继承自NoteBase
        title (str | None): 笔记标题，继承自NoteBase
        content (str | None): 笔记内容，继承自NoteBase
        is_published (bool): 是否发布，继承自NoteBase

    Config:
        from_attributes (bool): 允许从对象属性中创建模型实例
    """
    id: int
    created_at: datetime
    # updated_at: datetime

    class Config:
        from_attributes = True

# 数据模型
class UserRegister(BaseModel):
    username: str
    password: str
    

class UserLogin(BaseModel):
    username: str
    password: str